home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: iiasa.ac.at!marek
- From: marek@iiasa.ac.at (Marek MAKOWSKI)
- Subject: delete[] and template questions
- Message-ID: <1996Jan30.165654.2033@iiasa.ac.at>
- Organization: IIASA, Laxenburg, Austria
- X-Newsreader: TIN [version 1.2 PL2]
- Date: Tue, 30 Jan 1996 16:56:54 GMT
-
- I would like to ask for comments on three easy questions illustrated
- by the following piece of code:
-
- template <class I, class T>
- void mVect<I,T>::resize(I new_size) {
- T *old = v;
- v = new T[new_size]; // T *v is a private member of mVect
- int size_of_elem = sizeof(T); // <--- question 3
- //
- // do something
- //
- delete[] old; // <--- questions 1 & 2
- }
-
- I have the following questions:
- 1. Is it absolutely robust and portable to delete[] old, even
- if a previous call was for new_size == 0 (or if v was allocated
- by the ctor for the size == 0) ?
- 2. Is it correct to assume that no destructor is called by this statement ?
- 3. Is there any risk involved in using sizeof(T) in this statement ?
-
- I used to be sure that the answers are:
- 1. Yes
- 2. Yes
- 3. No
-
- However, I have recently started to port an application developed
- with SunPro (previously ported to Borland and checked with the
- Bounds-Checker32).
- The Watcom code blows-up on the delete[] statement (if a previous
- call was for new_size == 0) and gives warnings whenever it sees the
- sizeof(T).
- Of course I should assume that I have somewhere a nasty bug that
- does not wake-up for Borland/Bounds-checher nor for SunPro.
- However, while waiting for the answer from Watcom on how to fix
- the installation problem of the debugger, I would like to clarify,
- if my answers to the above questions are correct.
-
- Thanks in advance for your time.
-
- Marek
- --
- Marek Makowski | Email: marek@iiasa.ac.at
- International Institute | Phone: (+43-2236) 807.561
- for Applied Systems Analysis | Fax: (+43-2236) 71.313
- A-2361 Laxenburg, Austria | Web: http://www.iiasa.ac.at
-